package com.wwwarehouse.taskcenter.fragment.job_point.step5;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.adapter.job_point.TaskPointUnitHavedUnitAdapter;
import com.wwwarehouse.taskcenter.bean.job_point.AddJobPointStep5HavedUnitResponseBean;
import com.wwwarehouse.taskcenter.bean.job_point.AddJobPointStep5LookItemMesResponseBean;

import java.util.ArrayList;

/**
 * @创建者 chenchao.
 * @创建时间 2017/10/25 18:57
 * @描述 ${TODO}
 */

public class ChooseJobUnitHavedUnitDetailFragment5 extends BaseFragment implements EasyPopupWindow.ChildClickListener {

    private View mView;
    private RecyclerView mTaskPointRecycleview;
    private StateLayout mSlLayout;
    private static final int pageSize = 2;
    private ArrayList<AddJobPointStep5HavedUnitResponseBean> currentList;
    private TaskPointUnitHavedUnitAdapter adapter;
    private String jobPointUkid;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_choose_object_detail_6, container, false);
        initView(mView);
        return mView;
    }


    @Override
    public void setTitle() {
    }

    @Override
    public void requestDatas() {

    }

    private void initView(View mView) {
        mTaskPointRecycleview = (RecyclerView) mView.findViewById(R.id.task_point_recycleview);
        mSlLayout = (StateLayout) mView.findViewById(R.id.sl_layout);

        mTaskPointRecycleview.setLayoutManager(new LinearLayoutManager(mActivity));

        jobPointUkid = getArguments().getString("jobPointUkid");

        int page = getArguments().getInt("page");
        ArrayList<AddJobPointStep5HavedUnitResponseBean> list = getArguments().getParcelableArrayList("dataList");

        currentList = new ArrayList<>();
        //人体工程学加密
        for (int i = (page - 1) * pageSize; i < (list.size() > page * pageSize ? page * pageSize : list.size()); i++) {
            currentList.add(list.get(i));
        }

        adapter = new TaskPointUnitHavedUnitAdapter(currentList, mActivity,this);

        mTaskPointRecycleview.setAdapter(adapter);
    }

    @Override
    public void getChildView(int i, View view) {

    }

    public void goToDetailPage(AddJobPointStep5HavedUnitResponseBean bean){
        AddJobPointStep5LookItemMesResponseBean selectBean = new AddJobPointStep5LookItemMesResponseBean();
        ArrayList<AddJobPointStep5LookItemMesResponseBean.ListBean> lists = new ArrayList<>();
        AddJobPointStep5LookItemMesResponseBean.ListBean mesResponseBean = null;
        int number = 0;

        for(AddJobPointStep5HavedUnitResponseBean.JbUnitFactorsBean jbUnitFactorsBean : bean.getJbUnitFactors()){
            mesResponseBean = new AddJobPointStep5LookItemMesResponseBean.ListBean();


            try {
                number = Integer.parseInt(jbUnitFactorsBean.getMemberNum());
            } catch (NumberFormatException e) {
                number= 1;
            }
            mesResponseBean.setCount(number);
            mesResponseBean.setCategoryName(jbUnitFactorsBean.getMemberName());
            mesResponseBean.setJustShow(true);
            mesResponseBean.setUnitName(jbUnitFactorsBean.getMenberNumUnit());
            mesResponseBean.setMetaCategoryUkid(jbUnitFactorsBean.getMemberUkid());
            lists.add(mesResponseBean);
        }
        selectBean.setList(lists);

        Bundle bundle = new Bundle();
        bundle.putParcelable("selectBean",selectBean);
        bundle.putString("jobPointUkid",jobPointUkid);
        bundle.putParcelable("selectBean" , selectBean);
        ChooseJobUnitJustShowallunitpagerFragment5  fragment5 = new ChooseJobUnitJustShowallunitpagerFragment5();
        fragment5.setArguments(bundle);
        pushFragment(fragment5);
    }


    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }
}
